<?php
namespace app\admin\controller;

use app\common\model\ManagerCompany as ManagerCompanyModel;
use app\common\model\Renzhensiyuan as RenzhensiyuanModel;
use app\common\model\Company as CompanyModel;
use app\common\model\ManagerPassword as ManagerPasswordModel;
use app\common\model\Manager as ManagerModel;
use app\common\model\ManagerDuty as ManagerDutyModel;
use app\common\model\Gather as GatherModel;
use app\common\model\Gatherreg as GatherregModel;
use app\common\model\Ilike as IlikeModel;
use app\common\model\ZhModules as ZhModulesModel;
use app\common\model\Member as MemberModel;
use app\common\model\BuddhistService as BuddhistServiceModel;
use app\common\model\ManagerJob as ManagerJobModel;
use app\common\model\AdminUser as AdminUserModel;
use app\common\model\Config as ConfigModel;

/**
 * 寺院控制器
 * Class Company
 * @package app\index\controller
 */
class Company extends Base
{
    /**
     * [getIndex  寺院列表]
     * @param $data['type'] 1查询单挑寺院数据 2入驻申请 3寺院活动 4查询单挑寺院活动数据
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getIndex()
    {
        $model = new CompanyModel;
        $rzmodel = new RenzhensiyuanModel;
        $amodel = new AdminUserModel;
        $data = input('param.');
        $this->getPageAndSize($data);
        $map = [];
        $map1 = [];
        $user = $this->user;
        if(!empty($data['type'])){
            if($data['type'] == 1){
                try{
                    $list = $model->findData($data['id']);
                    $list['content'] = get_img_thumb_url(percent1($list['content']),config('domain_name').'/');
                }catch(\Exception $e){
                    systembug($e->getMessage(),1,'admin/Company/getIndex?type=1');
                    return admin_json(-1, '获取失败'.$e->getMessage());
                }
                $http = substr($list['compic'],0,4);
                if($http != 'http'){
                    $list['compic'] = config('domain_name').$list['compic'];
                }
                writelog('查看寺院--'.$data['id'],0,$user);
                return admin_json(1,'获取成功',$list);
            }elseif ($data['type'] == 2){
                try{
                    $count = $rzmodel->getCounts($map1);//满足条件的总数
                    $allpage = intval(ceil($count / $this->size));//总页数
                    $lists = $rzmodel->getlists($map1,$this->from, $this->size,'m.username,r.id,r.comname,r.addr,r.name,r.tel,r.addtime,r.status,r.city,r.compic,r.zongpai,r.duty,r.activepic,r.jiedie,r.cid,r.uid');
                }catch(\Exception $e){
                    systembug($e->getMessage(),1,'admin/Company/getIndex?type=2');
                    return admin_json(-1, '获取失败'.$e->getMessage());
                }
                writelog('查看寺院入驻列表',0,$user);
                return admin_json(1,'获取成功',[
                    'count' => $count,//总记录数
                    'allpage' => $allpage,  //总页数
                    'lists' => $lists,  //列表数据
                ]);
            }elseif ($data['type'] == 3){
                $gmodel = new GatherModel;
                $this->getPageAndSize($data);
                $map['g.states'] = ['in','0,1'];
                if (is_array($data)) {
                    if (!empty($data['con'])) {
                        $map['g.title|c.comname'] = ['like', "%" . $data['con'] . "%"];
                    }
                    if(!empty($data['time_type'])){
                        if($data['time_type'] == 1){
                            $map['g.endtime'] = ['between',[strtotime($data['start']),strtotime($data['end'])]];
                        }
                        if($data['time_type'] == 2){
                            $map['g.addtime'] = ['between',[strtotime($data['start']),strtotime($data['end'])]];
                        }
                    }
                }
                try{
                    $count = $gmodel->getCount($map);//满足条件的总数
                    $allpage = intval(ceil($count / $this->size));//总页数
                    $lists = $gmodel->getlist($map,$this->from, $this->size);
                    $grmodel = new GatherregModel;
                    foreach($lists as $k=>$v){
                        $lists[$k]['jnum'] = $v['num'];
                        $http = substr($v['cover'],0,4);
                        if($http != 'http'){
                            $lists[$k]['cover'] = config('domain_name').$v['cover'];
                        }
                        $map1['gather_id'] = $v['id'];
                        $lists[$k]['num'] = $grmodel->getCount($map1);
                        $lists[$k]['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
                        $lists[$k]['endtime'] = date('Y-m-d H:i:s',$v['endtime']);
                        $lists[$k]['activetime'] = date('Y-m-d H:i:s',$v['activetime']);
                    }
                }catch(\Exception $e){
                    systembug($e->getMessage(),1,'admin/Company/getIndex?type=3');
                    return admin_json(-1, '获取失败'.$e->getMessage());
                }

                writelog('查看寺院活动',0,$user);
                return admin_json(1,'获取成功',[
                    'count' => $count,//总记录数
                    'allpage' => $allpage,  //总页数
                    'lists' => $lists,  //列表数据
                ]);
            }elseif($data['type'] == 4){
                $gmodel = new GatherModel;
                try{
                    $list = $gmodel->findData($data['id']);
                    $list['addtime'] = date('Y-m-d H:i:s',$list['addtime']);
                    $list['endtime'] = date('Y-m-d H:i:s',$list['endtime']);
                    $list['starttime'] = date('Y-m-d H:i:s',$list['starttime']);
                }catch(\Exception $e){
                    systembug($e->getMessage(),1,'admin/Company/getIndex?type=4');
                    return admin_json(-1, '获取失败'.$e->getMessage());
                }
                $http = substr($list['cover'],0,4);
                if($http != 'http'){
                    $list['cover'] = config('domain_name').$list['cover'];
                }
                writelog('根据id查看寺院活动--'.$data['id'],0,$user);
                return admin_json(1,'获取成功',$list);
            }
        }else{
            $map['states'] = ['gt',0];
        }

        if (is_array($data)) {
            if (!empty($data['con'])) {
                $map['phone|comname'] = ['like', "%" . $data['con'] . "%"];
            }
            if (!empty($data['province'])) {
                $map['province'] = $data['province'];
            }
            if (!empty($data['city'])) {
                $map['city'] = $data['city'];
            }
            if (!empty($data['qu'])) {
                $map['qu'] = $data['qu'];
            }
            if(isset($data['info'])){
                if(!empty($data['info']) || $data['info'] === '0'){
                    $map['info'] = $data['info'];
                }
            }
            if(isset($data['info'])) {
                if (!empty($data['info1']) || $data['info1'] === '0') {
                    $map['info1'] = $data['info1'];
                }
            }
        }

        try{
            $field = 'id,info,info1,comname,province,city,qu,compic,phone,addtime,states,remarks,contract,fahao,focus,ispo,update_time,istop,istop1,jieyuan_isshow,read_num,bj_music,alllog,log,admin_id,type';
            if(!empty($data['alllog'])){
                $order = ['alllog'=>$data['alllog']];
            }elseif(!empty($data['log'])){
                $order = ['log'=>$data['log']];
            }else{
                $order = ['ispo'=>'desc','id' => 'desc'];
            }
            if($user['is_zhu'] == 2){
                $map['admin_id'] = $user['id'];
            }else{
                $field .= ',is_show';
            }

            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map,$this->from, $this->size,$field,$order);
            foreach($lists as $k=>$v){
                $http = substr($v['compic'],0,4);
                if($http != 'http'){
                    $lists[$k]['compic'] = config('domain_name').$v['compic'];
                }
//                $mmodel = new ManagerModel;
                $mcmodel = new ManagerCompanyModel;
                $map1['comid'] = $v['id'];
                $map1['status'] = 1;
                $lists[$k]['person_num'] = $mcmodel->getAllCount($map1);

                $imodel = new IlikeModel();
                $focus = $imodel->getAllCount(['status'=>1,'itemid'=>$v['id']]);
                $lists[$k]['zfocus'] = $focus;
                if($v['update_time'] != '1970-01-01 08:00:00'){
                    $lists[$k]['addtime'] = strtotime($v['update_time']);
                }
//                $manager = $mmodel->findData($v['manager_id'],'id','tel');
//                $member = $memodel->findData($manager['tel'],'tel','tel,img,username');
//                $lists[$k]['admin'] = $member;

                $admin = $amodel->findData($v['admin_id'],'id','username');
                $lists[$k]['ht_admin'] = $admin['username'];
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/getIndex');
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看寺院列表',0,$user);
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
    /**
     * [postAdd  添加寺院]
     * @param ftype 1添加寺院活动
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function postAdd()
    {
        $model = new CompanyModel;
        $gmodel = new GatherModel;
        $mmodel = new MemberModel;
        $cmodel = new ConfigModel;
//        $mmodel = new ManagerPasswordModel;
//        $fmodel = new ManagerModel;
//        $mcmodel = new ManagerCompanyModel;
//        $mdmodel = new ManagerDutyModel;
//        $nmodel = new NodeSonModel;
        $rmodel = new RenzhensiyuanModel;
        $data = input('param.');
        $data['addtime'] = time();
//        $map = [];
//        $map1 = [];
//        $map2 = [];
        $user = $this->user;

        if(!empty($data['ftype'])){
            if($data['ftype'] == 1){
                try{
                    $data['starttime'] = strtotime($data['starttime']);
                    $data['endtime'] = strtotime($data['endtime']);
//                    $data['activetime'] = strtotime($data['activetime']);
                    $id = $gmodel->addData($data);
                }catch(\Exception $e){
                    return admin_json(-1, '添加失败'.$e->getMessage());
                }
                writelog('添加寺院活动--'.$id,0,$user);
                return admin_json(1,'添加成功');
            }
        }
        $data['states'] = 1;
        $data['contract'] = 1;
        try{
            $company = $model->findData($data['comname'],'comname');
            if(!empty($company)){
                return admin_json(-1,'该寺院已存在！');
            }
            if(!empty($data['renzheng_id'])){
                $rmodel->editData(['id'=>$data['renzheng_id'],'status'=>1]);
                $renzheng = $rmodel->findData($data['renzheng_id'],'id','uid');
                $member = $mmodel->findData($renzheng['uid'],'id','id,quality');
                add_quality($member['id'],21,$member['quality'],3);
            }else{
                $renzhen = $rmodel->findOne(['comname'=>$data['comname'],'status'=>0]);
                if(!empty($renzhen)){
                    return admin_json(-1,'在入驻申请处填写！');
                }
            }


            $data['admin_id'] = $user['id'];
            $id = $model->addData($data);

//            $manager = $fmodel->findData($data['manager_id'],'id','tel,comid');
//            if(empty($manager['comid'])){
//                $fmodel->editData(['id'=>$data['manager_id'],'comid'=>$id]);
//            }
            if(!empty($data['renzheng_id'])){
                $rmodel->editData(['id'=>$data['renzheng_id'],'cid'=>$id]);
            }
//            $pass = getRandom(12);
//            $param = array(
//                'comid' => $id,
//                'mid' => $data['manager_id'],
//                'password' => md5(md5($pass) . config('admin.manager_password_halt')),
//                'addtime' => time(),
//                'pass' => $pass,
//                'tel' => $manager['tel']
//            );
//            $mmodel->addData($param);
//            $mcmodel->addData(['comid'=>$id,'mid'=>$data['manager_id'],'addtime'=>time()]);

        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/postAdd');
            return admin_json(-1, '添加失败'.$e->getMessage());
        }
        writelog('添加寺院--'.$id,0,$user);
        return admin_json(1,'添加成功',$id);
    }

    /**
     * [postAdd  修改寺院]
     * @param ftype 1修改寺院活动 2审核入驻
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function postEdit()
    {
        $model = new CompanyModel;
//        $mmodel = new ManagerPasswordModel;
//        $fmodel = new ManagerModel;
//        $mcmodel = new ManagerCompanyModel;
        $data = input('param.');
        $user = $this->user;
        if(!empty($data['ftype'])){
            if($data['ftype'] == 1){
                $gmodel = new GatherModel;
                $data['edittime'] = time();
                try{
                    $data['starttime'] = strtotime($data['starttime']);
                    $data['endtime'] = strtotime($data['endtime']);
                    $data['activetime'] = strtotime($data['activetime']);
                    $id = $gmodel->editData($data);
                }catch(\Exception $e){
                    systembug($e->getMessage(),1,'admin/Company/postEdit?ftype=1');
                    return admin_json(-1, '修改失败'.$e->getMessage());
                }
                writelog('修改寺院活动--'.$id,0,$user);
                return admin_json(1,'修改成功');
            }elseif($data['ftype'] == 2){
                try{
                    $rzmodel = new RenzhensiyuanModel;
                    $id = $rzmodel->editData(['status'=>$data['status'],'id'=>$data['id']]);
                }catch(\Exception $e){
                    systembug($e->getMessage(),1,'admin/Company/postEdit?ftype=2');
                    return admin_json(-1, '审核失败'.$e->getMessage());
                }
                writelog('审核入驻--'.$id,0,$user);
                return admin_json(1,'审核成功');
            }
        }
        try{
            $map = [];
            if(!empty($data['info'])){
                if($data['info'] == 1){
                    $map['info'] = 1;
                    $rcount = $model->getAllCount($map);
                    if($rcount >= 3){
                        return admin_json(-1, '首页只能推荐3个');
                    }
                }
                $name = '首页推荐';
            }
            if(!empty($data['info1'])) {
                if ($data['info1'] == 1) {
                    $map['info1'] = 1;
                    $rcount = $model->getAllCount($map);
                    if ($rcount >= 3) {
                        return admin_json(-1, '古刹只能推荐3个');
                    }
                }
                $name = '寺院推荐';
            }
            if(!empty($data['istop'])) {
                if ($data['istop'] == 1) {
                    $map['istop'] = 1;
                    $rcount = $model->getAllCount($map);
                    if ($rcount >= 1) {
                        return admin_json(-1, '只能置顶1个');
                    }
                }
                $name = '首页置顶';
            }
            if(!empty($data['istop1'])) {
                if ($data['istop1'] == 1) {
                    $map['istop1'] = 1;
                    $rcount = $model->getAllCount($map);
                    if ($rcount >= 1) {
                        return admin_json(-1, '只能置顶1个');
                    }
                }
                $name = '寺院置顶';
            }
//            $company = $model->findData($data['id'],'id','manager_id');
            $id = $model->editData($data);
//            if($company['manager_id'] != $data['manager_id']){
//                $manager = $fmodel->findData($data['manager_id'],'id','tel');
//                $mpass = $mmodel->findOne(['comid'=>$data['id'],'mid'=>$data['manager_id']]);
//                $mcompany = $mcmodel->findOne(['comid'=>$data['id'],'mid'=>$data['manager_id']]);
//                if(empty($mpass)){
//                    $pass = getRandom(12);
//                    $param = array(
//                        'comid' => $id,
//                        'mid' => $data['manager_id'],
//                        'password' => md5(md5($pass) . config('admin.manager_password_halt')),
//                        'addtime' => time(),
//                        'pass' => $pass,
//                        'tel' => $manager['tel']
//                    );
//                    $mmodel->addData($param);
//                }else{
//                    $param = array(
//                        'dutyid' => 0,
//                        'states' => 1,
//                        'id' => $mpass['id']
//                    );
//                    $mmodel->editData($param);
//                }
//                if(empty($mcompany)){
//                    $mcmodel->addData(['comid'=>$id,'mid'=>$data['manager_id'],'addtime'=>time(),'dutyid'=>0]);
//                }else{
//                    $mcmodel->editData(['id'=>$mcompany['id'],'dutyid'=>0,'status'=>1]);
//                }
//                $name = '换绑法师';
//            }
            if(empty($name)){
                $name = '编辑寺院';
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/postEdit');
            return admin_json(-1, '修改失败'.$e->getMessage());
        }
        writelog('修改寺院--'.$id.$name,0,$user);
        return admin_json(1,'修改成功');
    }
    /**
     * [getDel  删除]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getDel()
    {
        $model = new GatherModel;
        $cmodel = new CompanyModel;
        $rmodel = new RenzhensiyuanModel;
        $param = input('param.');
        $user = $this->user;
        if(!empty($param['company'])){
            try{
                $company = $cmodel->findData($param['id'],'id');
                if($company['istop'] == 1 || $company['istop1'] == 1){
                    return admin_json(-1,'请先取消置顶！');
                }
                if($company['info'] == 1 || $company['info1'] == 1){
                    return admin_json(-1,'请先取消推荐！');
                }
                $res = $cmodel->deleteFalseData(['id' => $param['id']],['states'=>-1,'deltime'=>time()]);
                $rmodel->changeStatus(['cid' => $param['id']],3);
            }catch(\Exception $e){
                systembug($e->getMessage(),1,'admin/Company/getDel');
                return admin_json(-1, '修改失败'.$e->getMessage());
            }
            writelog('删除寺院'.$param['id'],0,$user);

            return admin_json(1,'删除寺院成功');
        }

        $id = input('param.id');
        $res = $model->deleteFalseData(['id' => $id],['states'=>-1]);
        writelog('删除寺院活动--'.$id,0,$user);

        return admin_json(1,'删除寺院活动成功');
    }
    /**
     * [getDel  根据活动id获取报名人]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getGatherByid()
    {
        $model = new GatherregModel;
        $param = input('param.');
        $user = $this->user;
        try{
            $list = $model->getList(['gather_id'=>$param['id']]);
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/getGatherByid');
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看活动'.$param['id'].'的报名人',0,$user);
        return admin_json(1, '获取成功',$list);
    }
    /**
     * [postInfo  推荐]
     * @param   type 1推荐至首页 2推荐至寺院
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function postInfo()
    {
        $model = new CompanyModel;
        $param = input('param.');
        $user = $this->user;
        try{
            if($param['type'] == 1){
                if($param['info'] == 1){
                    $count = $model->getCompanyCount(['info'=>1]);
                    if($count >= 2){
                        return admin_json(2, '推荐数量超限！');
                    }
                }
                $model->editData(['id'=>$param['id'],'info'=>$param['info']]);
            }elseif($param['type'] == 2){
                if($param['info'] == 1){
                    $count = $model->getCompanyCount(['info1'=>1]);
                    if($count >= 2){
                        return admin_json(2, '推荐数量超限！');
                    }
                }
                $model->editData(['id'=>$param['id'],'info1'=>$param['info']]);
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/postInfo');
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('推荐寺院info:'.$param['info'].',id:'.$param['id'],0,$user);
        return admin_json(1, '推荐成功');
    }
    /**
     * [getAll  寺院列表]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getAll()
    {
        $param = input('param.');
        $model = new CompanyModel;
        $map = [];
        $user = $this->user;
        try{
            if(!empty($param['comname'])){
                $map['comname'] = ['like', "%" . $param['comname'] . "%"];;
            }
            $map['states'] = ['neq',-1];
            $list = $model->getAllData($map,'id','id,comname');
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/getAll');
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('获取寺院列表', 0,$user);
        return admin_json(1, '获取成功',$list);
    }
    /**
     * [getCate 寺院回收站]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getRecall(){
        $model = new CompanyModel;
        $data = input('param.');
        $this->getPageAndSize($data);
        $map = [];
        $user = $this->user;
        try{
            $map['states'] = -1;
            $map['deltime'] = ['LT',time()+3600*24*30];
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map,$this->from, $this->size);

            foreach($lists as $k=>$v){
                $http = substr($v['compic'],0,4);
                if($http != 'http'){
                    $lists[$k]['compic'] = config('domain_name').$v['compic'];
                }
                $mcmodel = new ManagerCompanyModel;
                $map1['comid'] = $v['id'];
                $map1['status'] = 1;
                $lists[$k]['person_num'] = $mcmodel->getAllCount($map1);

                $imodel = new IlikeModel();
                $focus = $imodel->getAllCount(['status'=>1,'itemid'=>$v['id']]);
                $lists[$k]['zfocus'] = $focus;
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/getRecall');
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看寺院回收站',0,$user);
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
    /**
     * [getCate 寺院回收站清空恢复]
     * @param $param['states'] 1回复 0清空
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getEmpty(){
        $param = input('param.');
        $model = new CompanyModel;
        $user = $this->user;
        try{
            $model->editData($param);
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/Company/getEmpty');
            return admin_json(-1, '失败'.$e->getMessage());
        }
        if($param['states'] == 1){
            $name = '恢复';
        }elseif($param['states'] == 0){
            $name = '清空';
        }
        writelog($name.'寺院回收站：id'.$param['id'].','.$param['states'],1,$user);
        return admin_json(1, '成功');
    }
    /**
     * [getDetial 获取寺院详情]
     * @param $param['states'] 1回复 0清空
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getDetial(){
        $param = input('param.');
        $model = new CompanyModel;
        $mmodel = new ManagerModel;
        $gmodel = new GatherModel;
        $grmodel = new GatherregModel;
        $bmodel = new BuddhistServiceModel;
        $mcmodel = new ManagerCompanyModel;
        $mjmodel = new ManagerJobModel;
        $mdmodel = new ManagerDutyModel;
        $memodel = new MemberModel;
        $user = $this->user;
        $map = [];
        $map1 = [];
        $map2 = [];
        $map3 = [];
        try{
            $data = $model->findData($param['id'],'id','id,comname,phone,addr');
            $data['guanwang'] = 'https://wx.fushan8.com/#/temple_info?id='.$data['id'];
            $data['houtai'] = 'http://www.zhsaas.com?id='.$data['id'];

            $map['comid'] = $data['id'];
            $map['states'] = ['neq','-1'];
            $map['type'] = 1;
            $shehui = $gmodel->getAllCount($map);
            $data['shehuinum'] = $shehui;

            $map1['comid'] = $data['id'];
            $map1['states'] = ['neq','-1'];
            $map1['type'] = 2;
            $yigong = $gmodel->getAllCount($map1);
            $data['yigongnum'] = $yigong;

            $map2['gr.comid'] = $data['id'];
            $map2['g.type'] = 1;
            $shehuigr = $grmodel->getCountes($map2);
            $data['shehuigrnum'] = $shehuigr;

            $map3['gr.comid'] = $data['id'];
            $map3['g.type'] = 2;
            $yigonggr = $grmodel->getCountes($map3);
            $data['yigonggrnum'] = $yigonggr;

            $bunum = $bmodel->getAllCount(['comid'=>$data['id']]);
            $data['buddhistnum'] = $bunum;

            $managernum = $mcmodel->getAllCount(['comid'=>$data['id'],'status'=>1]);
            $data['managernum'] = $managernum;

            $mancom = $mcmodel->getlist(['comid'=>$data['id'],'status'=>1],0,15,'id,dutyid,mid,jobid,addtime');
            foreach($mancom as &$v){
                $mem = $mmodel->getByConditonsOne(['m.id'=>$v['mid']],'am.username,am.tel');
                if(!empty($v['jobid'])){
                    $job = $mjmodel->findData($v['jobid'],'id','job');
                    $v['job'] = $job['job'];
                }else{
                    $v['job'] = '暂无';
                }
                if(empty($v['dutyid'])){
                    $v['duty'] = '最高管理';
                }else{
                    $duty = $mdmodel->findData($v['dutyid'],'id','duty');
                    $v['duty'] = $duty['duty'];
                }
                $v['username'] = $mem['username'];
                $v['tel'] = $mem['tel'];
                $member = $memodel->findData($mem['tel'],'tel','img');
                $http = substr($member['img'],0,4);
                if($http != 'http'){
                    $v['img'] = config('domain_name').'/'.$member['img'];
                }else{
                    $v['img'] = $member['img'];
                }
                $v['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
            }
            $data['manager'] = $mancom;
//            $data['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
        }catch(\Exception $e){
            return admin_json(-1, '失败'.$e->getMessage());
        }
        writelog('查看寺院详情',1,$user);
        return admin_json(1, '成功',$data);
    }
    /**
     * [getmodules 获取模块]
     * @param $param['states'] 1回复 0清空
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getModules()
    {
        $param = input('param.');
        $model = new CompanyModel;
        $zmodel = new ZhModulesModel;
        try{
            $data = $model->findData($param['id'],'id','modules');
            $moren = $zmodel->getAllData(['status'=>1],'tid','tid,id,name,img,url,is_show','asc');
            if(empty($data['modules'])){

            }else{
                $data = unserialize($data['modules']);
                $ids = array_column($data, 'tid');
                $new_data = [];
                foreach($moren as $k=>$v){
                    if(!in_array($v['tid'],$ids)){
                        $new_data[] = $v;
                    }
                }
                $moren = array_merge($data,$new_data);
//                $moren = $data;
//                foreach($moren as $k=>$v){
//                    if(!empty($data[$k]['is_show'])){
//                        $moren[$k]['is_show'] = $data[$k]['is_show'];
//                    }
//                    $moren[$k] = $data[$k];
//                }
            }
        }catch(\Exception $e){
            return admin_json(-1, '失败'.$e->getMessage());
        }
        return admin_json(1, '成功',$moren);
    }
    /**
     * [getmodules 获取模块]
     * @param $param['states'] 1回复 0清空
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function postAddmodules()
    {
        $param = input('param.');
        $model = new CompanyModel;
        try{
            if(!empty($param['modules'])){
                $param['modules'] = serialize($param['modules']);
            }
            $model->editData($param);
        }catch(\Exception $e){
            return admin_json(-1, '编辑失败'.$e->getMessage());
        }
        return admin_json(1, '编辑成功');
    }

}